using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Collections;
using System.Collections.Generic;

namespace BlogEngine.Core
{
	public class PhotoEffect : BlogBase<PhotoEffect>
	{

		/// <summary>
		/// Initializes a new instance of the <see cref="PhotoEffect"/> class.
		/// </summary>
		public PhotoEffect()
			: base()
		{
			OnLoad = PhotoProvider.Fill;
		}

		private string _PhotoEffectName;
		/// <summary>
		/// Gets or sets the name of the photo effect 
		/// </summary>
		public string PhotoEffectName
		{
			get
			{
				return _PhotoEffectName;
			}
			set
			{
				if (_PhotoEffectName != value) MarkChanged("PhotoEffectName");
				_PhotoEffectName = value;
			}
		}

		private IPhotoEffect _PhotoEffect;
		/// <summary>
		/// Gets the photo effect method
		/// </summary>
		public IPhotoEffect Effect
		{
			get
			{
				if (_PhotoEffect == null)
					_PhotoEffect = PhotoEffectCollection.GetPhotoEffect(PhotoEffectName);

				return _PhotoEffect;
			}
		}

		private PhotoEffectParameters _parameters = new PhotoEffectParameters();
		/// <summary>
		/// Gets the photo effect parameters
		/// </summary>
		public PhotoEffectParameters Parameters
		{
			get
			{
				return _parameters;
			}
		}

		/// <summary>
		/// Gets if the item has been changed.
		/// </summary>
		public override bool IsChanged
		{
			get
			{
				if (base.IsChanged)
					return true;

				if (Parameters.IsChanged)
					return true;

				return false;
			}
		}

		/// <summary>
		/// Saves the object to the database.
		/// </summary>
		public new void Save()
		{
			DateModified = DateTime.Now;
			base.Save();
			Parameters.IsChanged = false;
		}


		#region Data Access

		static internal BlogEngine.Core.Provider.Interfaces.IPhotoEffects PhotoProvider = BlogEngine.Core.Provider.BlogService.Provider.GetInterface<BlogEngine.Core.Provider.Interfaces.IPhotoEffects>();

		protected override void DataDelete()
		{
			PhotoProvider.Delete(this);
		}

		protected override void DataInsert()
		{
			PhotoProvider.Insert(this);
		}

		protected override PhotoEffect DataSelect(Guid id)
		{
			return PhotoProvider.Select(id);
		}

		protected override void DataUpdate()
		{
			PhotoProvider.Update(this);
		}

		private static int Dummy = OverrideOnLoad();

		private static int OverrideOnLoad()
		{
			OnLoad = PhotoProvider.Fill;
			return 0;
		}

        #endregion
	}
}
